﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - StudentMark" 
*/ 

component 
	displayname="public.service.db.senate.sequence.StudentMark" 
	output=false 
	accessors=true 
	{

	property type="string" name="StudentID" hint="学号";
	property type="string" name="CourseID" hint="课程ID";
	property type="string" name="TermID" hint="学期";
	property type="string" name="TaskType" hint="任务类型";
	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则 - 由于老系统数据主键重复， 取bookedcourse_Id区分"
	*/
	public string function getID() output=false {
		
		var nextID = getStudentID() & "," & getCourseID() & "," & getTermID() & getTaskType();
		
		/* 
			主键生成规则 
			
			选课号36位 8位学号 , 6位课程号 , 3位学期代码+教学任务类别

			Unique: STU_ID, CID, TERM_ID, TASK_TYPE
		*/
		
		return nextID;
	}
	
	/**
	* @hint "自定义主键规则bookedcourse_Id，仅作为唯一性区分"
	*/
	public string function getBoodedCourseId() output=false {
		
		sql = "	SELECT
					  bookedcourse_id
				FROM
					  t_student_mark 
				WHERE bookedcourse_id is not null 
				ORDER BY
					  bookedcourse_id DESC ";
		queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );	
		
		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		var nextID = rs_check.bookedcourse_id +1 ;
		
		/* 
			主键生成规则 
			
			选课号36位 8位学号 , 6位课程号 , 3位学期代码+教学任务类别

			Unique: STU_ID, CID, TERM_ID, TASK_TYPE
		*/
		
		return nextID;
	}

}

</cfscript>